import gdata.spreadsheet.service
import gdata.service
import atom.service
import gdata.spreadsheet
import atom
from getpass import getpass
import sys

if not sys.argv[1:]:
  user = raw_input("User:")
  pw = getpass()
elif not sys.argv[2:]:
  user = sys.argv[1]
  pw = getpass()
else:
  (user, pw) = sys.argv[1:3]
  

url='https://spreadsheets.google.com/spreadsheet/ccc?key=0AvCncvgg6JftdE85RHFxeGE3OVo1LUhNTmE4d0J3UXc&hl=en_US'

key='0AvCncvgg6JftdE85RHFxeGE3OVo1LUhNTmE4d0J3UXc'

client = gdata.spreadsheet.service.SpreadsheetsService()
client.source = "Spreadsheets UOIT Pages"
client.email = user
client.password = pw
client.ProgrammaticLogin()
sheets = client.GetWorksheetsFeed(key)

# Print the worksheets
for (i, wksheet) in enumerate(sheets.entry):
  print "%d. %s" % (i, wksheet.title.text)
  wskey = wksheet.id.text.split('/')[-1]

# Print the content of the first worksheet
listfeed = client.GetListFeed(key, wskey)
for (j, cell) in enumerate(listfeed.entry):
  k = cell.custom['property'].text
  v = cell.custom['value'].text
  print '\t%d. "%s: %s..."' % (j, k, v[0:30])

